import api from '../../utils/api'
Page({
    data: {
        notices: [],       // 轮播图公告数据
        masters: [],       // 回收师傅数据
        stations: [],      // 回收站数据
        loading: true,      // 加载状态
        showLogin: false,   // 是否显示登录弹窗
    },

    onLoad() {
        this.loadMockData()
    },
    // 加载模拟数据
    loadMockData() {
        // 模拟轮播图数据
        const mockNotices = [
            {
                id: 1,
                image: 'https://img.freepik.com/free-photo/garbage-collection-concept_23-2148894387.jpg',
                link: '/pages/notice/detail?id=1',
                title: '环保回收活动'
            },
            {
                id: 2,
                image: 'https://img.freepik.com/free-photo/group-people-volunteering-community_23-2149231200.jpg',
                link: '/pages/notice/detail?id=2',
                title: '新用户优惠'
            }
        ]

        // 模拟回收师傅数据
        const mockMasters = [
            {
                id: 101,
                name: '张师傅',
                avatar: 'https://example.com/avatar1.jpg',
                score: 4.8,
                service_area: ['朝阳区', '海淀区'],
                distance: 1.2,
                phone: '13800138000'
            },
            {
                id: 102,
                name: '李师傅',
                avatar: 'https://example.com/avatar2.jpg',
                score: 4.9,
                service_area: ['东城区', '西城区'],
                distance: 2.5,
                phone: '13800138001'
            }
        ]

        // 模拟回收站数据
        const mockStations = [
            {
                id: 201,
                name: '朝阳环保回收站',
                address: '北京市朝阳区建国路88号',
                business_hours: '08:00-18:00',
                phone: '010-88889999'
            },
            {
                id: 202,
                name: '海淀绿色回收中心',
                address: '北京市海淀区中关村大街1号',
                business_hours: '09:00-17:00',
                phone: '010-66667777'
            }
        ]

        // 设置模拟数据
        this.setData({
            notices: mockNotices,
            masters: mockMasters,
            stations: mockStations,
            loading: false
        })
    },

    // 轮播图点击事件
    onBannerTap(e) {
        const url = e.currentTarget.dataset.url
        if (url) {
            wx.navigateTo({
                url: url
            })
        }
    },

    // 搜索框点击事件
    onSearchClick() {
        wx.navigateTo({
            url: '/pages/search/search'
        })
    },

    // 导航到预约下单页
    navigateToOrder() {
        wx.navigateTo({
            url: '/pages/order/order'
        })
    },

    // 导航到价格查询页
    navigateToPrice() {
        wx.navigateTo({
            url: '/pages/price/price'
        })
    },

    // 导航到地图页
    navigateToMap() {
        wx.navigateTo({
            url: '/pages/map/map'
        })
    },

    // 查看更多师傅
    viewMoreMasters() {
        wx.navigateTo({
            url: '/pages/master/list'
        })
    },

    // 回收站点击事件
    onStationClick(e) {
        const id = e.currentTarget.dataset.id
        wx.navigateTo({
            url: `/pages/station/detail?id=${id}`
        })
    }
})